import { showSuccessToast } from 'vant';
import { ref } from 'vue';

import { transformOrder } from '../api';
import TransOrderConfig from '../models/TransOrderConfig';

const useTransConfig = () => {
  const params = ref<TransOrderConfig>(new TransOrderConfig());

  const state = ref({
    loading: false,
  });

  const handleTransform = async () => {
    try {
      state.value.loading = true;
      const { data } = await transformOrder(params.value);
      showSuccessToast(data.msg || '转换成功');
    } catch (error) {
      //
    } finally {
      state.value.loading = false;
    }
  };

  return {
    params,
    state,
    handleTransform,
  };
};

export default useTransConfig;
